<script setup lang="ts">
import { useUserStore } from '@/stores/user'
import { ElMessage, ElMessageBox } from 'element-plus'
import router from '@/router'
const store = useUserStore()

const logout = () => {
  ElMessageBox.confirm('确定要退出吗？', '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning',
  }).then(() => {
    store.removeToken()
    router.push('/login')
    ElMessage.success('退出成功')
  })
}
</script>

<template>
  <el-container class="layout-container">
    <el-aside width="200px">
      <div class="logo"></div>

      <el-menu
        background-color="#023"
        text-color="#fff"
        style="border-right: none"
        :default-active="$route.path"
        router
      >
        <el-menu-item index="/home"> <i class="el-icon-s-home"></i> 数据概览 </el-menu-item>

        <el-menu-item index="/article"> <i class="el-icon-document"></i> 内容管理 </el-menu-item>

        <el-menu-item index="/publish"> <i class="el-icon-s-promotion"></i> 发布文章 </el-menu-item>
      </el-menu>
    </el-aside>

    <el-container>
      <el-header>
        <span>用户</span>
        <el-link icon="el-icon-unlock" :underline="false" @click="logout()">退出</el-link>
      </el-header>

      <el-main> <router-view></router-view> </el-main>
    </el-container>
  </el-container>
</template>

<style scoped lang="less">
.layout-container {
  height: 100vh;
  width: 100%;

  .el-aside {
    background-color: #023;

    .logo {
      width: 200px;
      height: 60px;
      background: #023 url('@/assets/images/logo.png') no-repeat center / 160px auto;
    }
  }

  .el-header {
    border-bottom: 1px solid #ddd;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 10px;
  }
}
</style>
